/***     
 * SP_FIVE_FLUSH: 8, // 同花
 */

var CardGroupType = require('./CardGroupType');
var FindSameCardValueTool = require('./../FindTool/FindSameCardValueTool');
var _ = require('./../Underscore');
var CardType = require('./../CardType');
var CardTool = require('./../CardTool');
var FindShunZiTool = require('../FindTool/FindShunZiTool');
var FindPairsTool = require('./../FindTool/FindPairsTool');
var FindSameCardTypeTool = require('../FindTool/FindSameCardTypeTool');


var GroupSameType = module.exports = {};

GroupSameType.getName = function() {
    return '同花';
};

GroupSameType.getType = function() {
    return CardGroupType.SP_FIVE_FLUSH;
};

GroupSameType.getMoreResult = function(_cardInfoList) {
    var groupList = FindSameCardTypeTool.getGroupTypeList(_cardInfoList);

    var findGroupMore = [];
    _.each(groupList, function(singleGroup) {
        singleGroup = _.sortBy(singleGroup, function(_cardInfo) {
            return _cardInfo.value;
        });
        var size = _.size(singleGroup);
        var findGroup = null;
        if (size == 5) {
            findGroup = singleGroup;
        } else if (size > 5) {
            var tmpList = _.partition(singleGroup, function(cardInfo, idx) {
                return idx >= (size - 5);
            });
            findGroup = tmpList[0];
        }
        if (!!findGroup) {
            var info = {
                findGroup: findGroup,
                otherGroup: _.difference(_cardInfoList, findGroup)
            }
            findGroupMore.push(info);
        }
    })

    var result = {
        isFind: _.size(findGroupMore) > 0,
        findGroupMore: findGroupMore
    };
    CardTool.LogResult(result, this.getName());
    return result;
};